//
//  NSIndexPath+WCExtensions.m
//  WabbitCode
//
//  Created by William Towe on 11/9/08.
//  Copyright 2008 Revolution Software. All rights reserved.
//

#import "NSIndexPath+WCExtensions.h"
#import "WCMacros.h"


@implementation NSIndexPath (WCExtensions)
- (NSUInteger)firstIndex; {
	return [self indexAtPosition:0]; 
}

- (NSUInteger)lastIndex; {
	return [self indexAtPosition:[self length] - 1];
}

- (NSString *)stringFromIndexPath; {
	NSMutableArray *indexObjects = [NSMutableArray array];
	NSUInteger length = [self length];
	NSUInteger indexes[length];
	
	[self getIndexes:indexes];
	
	for (NSUInteger index = 0; index < length; index++)
		[indexObjects addObject:[NSNumber numberWithUnsignedInteger:indexes[index]]];
	
	return [indexObjects componentsJoinedByString:@","];
}

- (NSIndexPath *)indexPathByIncrementingLastIndex;
{
	NSUInteger lastIndex = [self lastIndex];
	NSIndexPath *temp = [self indexPathByRemovingLastIndex];
	return [temp indexPathByAddingIndex:++lastIndex];
}
@end
